VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 1  'vbDataSource
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Record"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'Copyright (C) 2011, 2012 Biergaizi
'License: GPL v3 or later.
Option Explicit
Private SQL As String
Private LastSQL As String
Private WithEvents rs As ADODB.Recordset
Attribute rs.VB_VarHelpID = -1
Private Writeable As Boolean

Private Sub Class_Initialize()
    Set rs = New ADODB.Recordset
End Sub

Private Sub Class_GetDataMember(DataMember As String, Data As Object)
    Set Data = rs
End Sub

Public Sub Selects(SQL)
    LastSQL = SQL
    On Error GoTo Reopen
    
    If Writeable = True Then
        rs.Open SQL, Database.Conn, adOpenStatic, adLockOptimistic
    Else
        rs.Open SQL, Database.Conn, adOpenStatic, adLockReadOnly
    End If
    
    If Not (rs.BOF = True And rs.EOF = True) Then
        rs.MoveFirst
    End If
    
    Exit Sub
    
Reopen:
    rs.Close
    rs.Open SQL, Database.Conn, adOpenStatic, adLockOptimistic
    
    If Not (rs.BOF = True And rs.EOF = True) Then
        rs.MoveFirst
    End If
End Sub

Public Property Get ReadOnly() As Boolean
    ReadOnly = Not (Writeable)
End Property

Public Property Let ReadOnly(Value As Boolean)
    Writeable = Not (Value)
End Property
